/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.custom;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 *
 * @author The Lunatics
 */
public class MyApplicationContextListener implements ServletContextListener {

    private static final String gameControllerStr = "gameController";
    
    private ScheduledExecutorService scheduler;

    @Override
    public void contextInitialized(ServletContextEvent event) {
    	GameController gameController = new GameController();
    	event.getServletContext().setAttribute(gameControllerStr, gameController);
        scheduler = Executors.newSingleThreadScheduledExecutor();
//        scheduler.scheduleAtFixedRate(new GameController(), 0, 8, TimeUnit.SECONDS);
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
    	GameController gameController = (GameController) event.getServletContext().getAttribute(gameControllerStr);
    	try {
    		event.getServletContext().removeAttribute(gameControllerStr);
    	} finally {
    		gameController.dispose();
    	}
    }

}